package com.daveychu.lingo.gui;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;

import javax.swing.JPanel;

import com.daveychu.lingo.model.Letter;
import com.daveychu.lingo.model.Lingo;

@SuppressWarnings("serial")
public class WordPanel extends JPanel {

	private Letter[] letters = new Letter[Lingo.NR_OF_LETTERS];

	public WordPanel() {
		for (int i = 0; i < letters.length; i++) {
			letters[i] = new Letter(' ');
		}
	}

	@Override
	public void paint(Graphics g) {
		g.setFont(new Font("monospaced", Font.PLAIN, 30));
		for (int i = 0; i < letters.length; i++) {
			if (letters[i].isPlacedCorrectly()) {
				g.setColor(Color.RED);
				g.fillRect(i * 30 - 10, 30, 40, 30);
				g.setColor(Color.BLACK);
				g.drawRect(i * 30 - 10, 30, 40, 30);
			} else if (letters[i].isInSolution()) {
				g.setColor(Color.YELLOW);
				g.fillOval(i * 30 - 10, 30, 40, 30);
				g.setColor(Color.BLACK);
				g.drawRect(i * 30 - 10, 30, 40, 30);
			}
			
			g.setColor(Color.BLACK);
			g.drawString(String.valueOf(letters[i].getLetter()), i * 30, 55);
		}
	}

	public void setLetters(Letter[] letters) {
		this.letters = letters.clone();
		repaint();
	}

	public void resetLetters() {
		for (int i = 0; i < letters.length; i++) {
			letters[i] = new Letter(' ');
		}
		repaint();
	}
}